<?php
/**
  * Smarty中文字符串截取
  * 天涯PHP博客 http://blog.phpha.com
  */
function smarty_modifier_msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true){
    $re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
    preg_match_all($re[$charset], $str, $match);
    $slice = join("", array_slice($match[0], $start, $length));
    if($suffix) return $slice . '...';
    return $slice;
}
?>